import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.service import Service
# from webdriver_manager.chrome import ChromeDriverManager

# 使用 webdriver_manager 自动管理 ChromeDriver
driver = webdriver.Chrome()

# 打开京东首页
driver.get("https://www.jd.com")

# 使用显式等待确保元素可操作
wait = WebDriverWait(driver, 10)  # 等待最多10秒
house_device = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="J_service"]/div[1]/ul/li[1]/a')))

# 创建 ActionChains 对象并执行鼠标悬停操作
action = ActionChains(driver)
action.move_to_element(house_device).perform()

# 等待5秒
time.sleep(5)

print("操作完成")
driver.quit()  # 关闭浏览器
